<?php namespace Home\Controller; 
//测试控制器
class IndexController extends CommonController{

	//构造函数
	public function __init()
	{
	}
	
    //首页
    public function index(){
    	//公共头部信息
    	$conf = array(
    		"title"=>"hdphp教学博客-首页",
		);
		//分离变量
		View::with('conf',$conf);
		//4.实例化文章表
		$articleModel = new \Common\Model\Article;
		//实例化分类表
		$cateModel = new \Common\Model\Category;
		//计总数不再回收站的文章总数
		$count = $articleModel->where("is_recycle",0)->count();
		//var_dump($count);
		$page = Page::row(2)->make($count);
		//文章表与分类表关联
		$data = $articleModel
				->join("category","category_cid","=","cid")
				->where("is_recycle",0)->orderBy("sendtime","DESC")->limit(Page::limit())->get();
				
		//var_dump($data);
		//获得每篇文章的所标签
		foreach ($data as $k => $v) {
			$data[$k]['tag'] = Db::table("article_tag")
								->join("tag","tag_tid","=","tid")
								->where("article_aid",$v['aid'])->lists("tid,tname");
		}

		View::with("page",$page);
		View::with("data",$data);
		
       View::make();
 
    }
}
